package com.gupaoedu.design.proxy.jdk;

import com.gupaoedu.design.proxy.Person;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * <p></p>
 *
 * @author Andy
 * @date 2018/3/12.
 */
public class JdkMeipo implements InvocationHandler{
    private Person target;

    public JdkMeipo(Person target) {
        this.target = target;
    }

    public Object proxy() {
        Class clazz = this.target.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆：我要给你找对象，现在已经拿到你的需求");
        System.out.println("开始物色");
        method.invoke(target, args);
        System.out.println("如果合适的话，就准备办事");
        return null;
    }
}
